#include "merge.h"

void merge(std::vector<int>& nums1, int m, std::vector<int>& nums2, int n)
{
	std::vector<int> temp;
	temp.clear();

	int num1_index = 0;
	int num2_index = 0;

	int count = m + n;

	while (count > 0)
	{
		if (num1_index >= m)
		{
			temp.push_back(nums2[num2_index]);
			num2_index++;
		}
		else if (num2_index >= n)
		{
			temp.push_back(nums1[num1_index]);
			num1_index++;
		}
		else if (nums1[num1_index] <= nums2[num2_index])
		{
			temp.push_back(nums1[num1_index]);
			num1_index++;
		}
		else if (nums1[num1_index] > nums2[num2_index])
		{
			temp.push_back(nums2[num2_index]);
			num2_index++;
		}

		count--;
	}

	nums1 = temp;
}
